package Server.ServerCore.Controller;

import Server.ServerCore.Model.Player.PlayerInstance;
import Server.ServerCore.Service.DataPacks.packRequest.SigleBuyIns_requst;
import Server.ServerCore.Service.DataPacks.packRespose.SigleBuyIns_response;
import Server.ServerCore.Service.Logic.HandleController;
import Server.ServerCore.Service.Logic.RegisterPack;
import Server.ServerCore.Service.service.PlayerManagerService;
import org.jboss.netty.buffer.ChannelBuffer;
import org.springframework.stereotype.Service;

/**
 * @author :石头哥哥<br/>
 *         Project:21Server
 *         Date: 13-4-17
 *         Time: 上午3:23
 *         SingleNoBuyInsController==217
 *        bug 询问保险完毕 保险面板没有消失
 */
@Service
public class SingleNoBuyInsController  extends HandleController {
    private static final long serialVersionUID = -1666375373802795231L;

    /**
     * 数据分解具体处理的函数
     *
     * @param buffer buffer
     * @param player player
     */
    @Override
    public void DispatchPack(ChannelBuffer buffer, PlayerInstance player) throws Exception {
        SigleBuyIns_requst sigleBuyInsRequst= (SigleBuyIns_requst) parseObject(buffer,SigleBuyIns_requst.class);
        int CircleUnitID=sigleBuyInsRequst.getCircleUnitID();
        SigleBuyIns_response sigleBuyInsResponse=new SigleBuyIns_response();

        if (player.getNowCrileUnitID()==CircleUnitID&&CircleUnitID!=5){
            int now= PlayerManagerService.getNextcircleUnitID(player,CircleUnitID);
            if (now<=4&&now!=-1){
                sigleBuyInsResponse.setNextcircleUnitID(now);
                player.setNowCrileUnitID(now);
                player.DirectSend(sigleBuyInsResponse.getJsonData(2,17));
            }else {//指向第一个  这里没有开始（保险完毕）
                now=player.getCircleUnitIDS().get(0);
                sigleBuyInsResponse.setNextcircleUnitID(now);
                if (now!=-1){player.setNowCrileUnitID(now);player.DirectSend(sigleBuyInsResponse.getJsonData(2,9));}

            }
        }


    }

    /**
     * 通过spring产生处理数据的controller，储存在数组中
     */
    @Override
    public void InitiController() {
        RegisterPack.GAME_CONTROLLERS[217]=this;
    }
}
